package com.atguigu.exer;
//使用同步方法来解决实现Runnable接口的线程安全问题
public class WindowsTest2 extends Thread {
    private static int ticket = 100;

    public static void main(String[] args) {
        WindowsTest2 wt1 = new WindowsTest2();
        WindowsTest2 wt2 = new WindowsTest2();
        WindowsTest2 wt3 = new WindowsTest2();
        wt1.setName("窗口1");
        wt2.setName("窗口2");
        wt3.setName("窗口3");
        wt1.start();
        wt2.start();
        wt3.start();
    }

    private static synchronized void show() {
        if (ticket > 0) {
            System.out.println(Thread.currentThread().getName() + ":卖票，票号为:" + ticket);
            ticket--;
        }
    }
}